import { SET_AUTHENTICATED, SET_USER, ADD_TAG_ITME, DEL_TAG_ITEM } from "./mutation-type";

export default {
  //是否授权
  [SET_AUTHENTICATED](state, { isAuthenticated }) {
    if (isAuthenticated) {
      state.isAuthenticated = isAuthenticated;
    } else {
      state.isAuthenticated = false;
    }
  },
  [SET_USER](state, { user }) {
    if (user) {
      state.user = user;
    } else {
      state.user = {};
    }
  },
  [SET_AUTHENTICATED](state) {
    state.isAuthenticated = false; //退出登录
  },


  [ADD_TAG_ITME](state, payLoad) {//增加tag

    let isExist = state.tags.find(item => item.title === payLoad.title)
    if (!isExist) {
      state.tags.push(payLoad)
    }


  },

  [DEL_TAG_ITEM](state, index) {//删除tag
    state.tags.splice(index, 1);
  }
};